package com.bbs.action;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.bbs.dao.TopicDao;
import com.bbs.dao.impl.IndexDaoImpl;
import com.bbs.dao.impl.TopicDaoImpl;
import com.bbs.model.Section;
import com.bbs.model.Topic;
import com.opensymphony.xwork2.ActionContext;

public class IndexAction extends BaseAction{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	//显示主页的方法 升级版
	public String indexPage() throws IOException{
		//获得request
		HttpServletRequest request = ServletActionContext.getRequest();
		//用map在页面上迭代 key:section value :list<topic>
		Map<Section, List<Topic>> rMap=new HashMap<Section, List<Topic>>();
		//向map里面放内容
		assembContent(rMap);
		//map 放入request对象中
		request.setAttribute("rMap", rMap);
		return "indexPage";
	}

	//显示主页的方法
	/*public String indexPage() throws IOException{
        TopicDao topicDao=new TopicDaoImpl();
        List<Topic> topics=topicDao.getTopicList();
        @SuppressWarnings("unchecked")
        Map<String, List<Topic>> request = (Map<String, List<Topic>>) ActionContext.
                getContext().get("request");
        request.put("topics", topics);
        return "indexPage";
}*/
	private void assembContent(Map<Section, List<Topic>> rMap) throws IOException{
		IndexDaoImpl impl=new IndexDaoImpl();
		impl.assembContent(rMap);
	}

}
